﻿/// <reference path="../Scripts/jquery-1.7.2.js" />
/// <reference path="../aaa/jqueryExtensions.js" />
/// <reference path="../Scripts/qunit.js" />
/// <reference path="../Scripts/sinon-1.3.4.js" />
/// <reference path="../Scripts/sinon-qunit-1.0.0.js" />


$(function () {
    module("Given non empty array", {
        setup: function () {
        }
    });

    test("When parameters are assigned, then full url is returned", function () {
        var httpRequestBuilder = new activityFeed.HttpRequestBuilder('www.test.pl');

        httpRequestBuilder.addParameter('p1', 'value1');
        httpRequestBuilder.addParameter('p2', 'value2');

        var url = httpRequestBuilder.createUrlWithQueryString();

        equal(url, "www.test.pl?p1=value1&p2=value2");
    });

    test("When parameter is null, then it's not added to url", function () {
        var httpRequestBuilder = new activityFeed.HttpRequestBuilder('www.test.pl');

        httpRequestBuilder.addParameter('p1', null);
        httpRequestBuilder.addParameter('p2', 'value2', 'defaultValue');

        var url = httpRequestBuilder.createUrlWithQueryString();

        equal(url, "www.test.pl?p2=value2");
    });

    test("When parameter value is same as default value, then it's not added to url", function () {
        var httpRequestBuilder = new activityFeed.HttpRequestBuilder('www.test.pl');

        httpRequestBuilder.addParameter('p1', 'defaultValue', 'defaultValue');
        httpRequestBuilder.addParameter('p2', 'value2');

        var url = httpRequestBuilder.createUrlWithQueryString();

        equal(url, "www.test.pl?p2=value2");
    });

    test("When parameter value caontains special characters, then url should be encoded", function () {
        var httpRequestBuilder = new activityFeed.HttpRequestBuilder('www.test.pl');

        httpRequestBuilder.addParameter('p1', 'aa/dd#%^&?');
        httpRequestBuilder.addParameter('p2', 'value2');

        var url = httpRequestBuilder.createUrlWithQueryString();

        equal(url, "www.test.pl?p1=aa%2Fdd%23%25%5E%26%3F&p2=value2");
    });
});